package com.java2_24;

import java.util.Scanner;
import java.util.ServiceConfigurationError;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

public class java2_24 {
    //    public static void main(String[] args) {
//        //非静态内部类的调用
//
//
//        Student1.ClassRoom sc = new Student1().new ClassRoom();
//
//
////        sc.show();
//
//
////        Student1 s = new Student1();
////        Student1.ClassRoom classRoom = s.getClassRoom();
////        classRoom.show("coco");
//        //Student1.ClassRoom1.show();
//        //不推荐
//
//
////        Student1.ClassRoom1 cs1 = new Student1.ClassRoom1();
////
////
////        cs1.show();
//
//        Student1.ClassRoom1 sc1 = new Student1.ClassRoom1();
//
//
//    }
//    public static void main(String[] args) {
//        //java异常 -- Error and Exception
////        int[] arr = null; //NullPointerException
////        arr[1] = 10;
////        int a = 10;
////        System.out.println(a/0); //ArithmeticException
//
////        int[] arr = new int[5];
////        for (int i = 0; i < arr.length + 1; i++) { //ArrayIndexOutOfBoundsException
////            arr[i] = i;
////        }
//
//
//    }
//    public static void main(String[] args) {
//        try {
////            int a = 10;
////            System.out.println(a/0);
////            int[] arr = new int[5];
////            for (int i = 0; i < arr.length+1; i++) {
////                arr[i] = i;
////            }
////            String name = null;
////            name = "zhangsan";
////        } catch (ArithmeticException e1) {
////            System.out.println("计算错误");
////            System.out.println(100/0);
////        } catch (ArrayIndexOutOfBoundsException e2){
////            System.out.println("数组越界");
////        } catch(NullPointerException e3) {
////            System.out.println("地址为空");
////        } catch (Exception e4){
////            System.out.println("就是有异常");
////        } finally {
////            System.out.println("完成");
////        }
////        //finally 必须输出 除了System.exit(0);
////
////
////    }
//
//
//}
//    public static void main(String[] args) {
//        //抛出异常
//        error(17);
//        error(27);
//
//
//
//    }
//    public static void error(int age) throws RuntimeException{
//        //
//        if(age<18 || age>40){
//            throw new AgeException();
//        }
//        System.out.println("当前年龄为：" + age);
//    }
    //捕获不会终止程序，但是抛出会
//    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        try {
//            System.out.print("请输入你的年龄：");
//            int number = sc.nextInt();
//            getAge(number);
//            System.out.println("成功");
//        } catch (ArithmeticException e1) {
//            String message = e1.getMessage();
//            System.out.println(message);
//        } catch (AgeException e2) {
//            System.out.println(e2.toString());
//        } catch (Exception e3) {
//            System.out.println("就是有错误");
//        } finally {
//            System.out.println("输入失败!!!");
//        }
//
//    }
//
//    private static void getAge(int age) throws AgeException {
//        if (age < 18 || age > 40) {
//            throw new AgeException("年龄范围有误");
//        }
//        System.out.println("输入年龄已被获取");
//    }
//    public static void main(String[] args) {
//        Card c = new Card();
//        ArrayList<String> list = Card.getList();
//        System.out.println(list);
//
//
//    }
//    public static void main(String[] args) {
//        //常用的Math方法
////        double n = -3.14;
////        System.out.println(Math.abs(n));
////        System.out.println(Math.absExact(-1649140328746132));
//        //两个绝对值 abs（） absExact（）
//        //向上向下取整
////        System.out.println(Math.ceil(3.14));
////        System.out.println(Math.ceil(-3.14));
////        System.out.println(Math.ceil(-3));
////        System.out.println(Math.floor(3.14));
////        System.out.println(Math.floor(-3.14));
////        System.out.println(Math.floor(-3));
////        System.out.println(Math.round(3.14));
////        System.out.println(Math.round(3.54));
////        System.out.println(Math.round(-3.14));
////        System.out.println(Math.round(-3.54));
////        System.out.println(Math.round(-3));
//        //先四舍五入
////        int a = 10;
////        int b = 20;
//////        if(a>b){
//////            System.out.println("较大的是" + a);
//////        }else {
//////            System.out.println("较大的是" + b);
//////        }
//////        int max = a > b ? a : b;
//////        System.out.println("较大的是" + max);
////        System.out.println("较大的是" + Math.max(a,b));
////        Scanner sc = new Scanner(System.in);
////        int num = sc.nextInt();
////        double powNum = Math.pow(num, 3);
////        System.out.println(powNum);
////        System.out.println(Math.cbrt(powNum));
////        int num = 81;
////        System.out.println(Math.sqrt(num));
//
//        //生成随机数
////        Random r = new Random();
////        int RandomNum = r.nextInt(20) + 1;
////        System.out.println(RandomNum);
////        System.out.println(Math.round(Math.random()*100));
//
//
//    }
//    public static void main(String[] args) {
//        System.out.println("系统正在运行......");
//        System.out.println("系统正在运行......");
//        System.out.println("系统正在运行......");
//        System.out.println("系统正在运行......");
//        //立即停止JVM虚拟机的运行
//        //System.exit(0);
//        System.exit(1); //异常
//        System.out.println("系统正在运行......");
//        System.out.println("系统正在运行......");
//        System.out.println("系统正在运行......");
//        System.out.println("系统正在运行......");
//
//
//
//    }
//    public static void main(String[] args) {
////        long be = System.currentTimeMillis();
////        System.out.println(be);
////        try{
////            int a = 10;
////            int b = 0;
////            System.out.println(a/b);
////        }catch (ArithmeticException e1){
////            e1.printStackTrace();
////        }catch(ArrayIndexOutOfBoundsException e2){
////            System.out.println(e2.toString());
////        }finally {
////            //System.exit(0);
////            System.out.println("运行结束！！！");
////        }
////        long end = System.currentTimeMillis();
////        System.out.println(end - be);
//        //finally优先执行
//        //运行速度过快导致相减之后的值为0；
//
//
//    }
//    public static void main(String[] args) {
//        long time1 = System.currentTimeMillis();
//        Scanner sc = new Scanner(System.in);
//        int i = sc.nextInt();
//        System.out.println(i);
//        long time2 = System.currentTimeMillis();
//        System.out.println(time2 - time1);
//        //为0是运行过快导致的
//
//    }
//    public static void main(String[] args) {
//        //数组复制
//        int[] arr1 = new int[10];
//        for (int i = 0; i < arr1.length; i++) {
//            arr1[i] = i;
//        }
//        int[] arr2 = new int[10];
//        System.arraycopy(arr1,0,arr2,0,10);
//        for (int i = 0; i < arr2.length; i++) {
//            System.out.print(arr2[i] + " ");
//        }
//
//    }
//    public static void main(String[] args) {
//        //数组复制（放到新的数组容器中）
//        Child c1 = new Child("zhangsan", 12);
//        Child c2 = new Child("lisi", 12);
//        Child c3 = new Child("wangwu", 12);
//        Child c4 = new Child("zhaoliu", 12);
//
//        Child[] children = {c1, c2, c3, c4};
//        People[] p = new People[4];
//        System.arraycopy(children,0,p,0,4);
//        for (int i = 0; i < p.length; i++) {
//            Child people = (Child) p[i];
//            System.out.println(people.toString());
//        }
//
//
//    }
//    public static void main(String[] args) {
////        Test t = new Test();
////        System.out.println(t.toString());
////        System.out.println(t);
//        //println里面有个toString方法
////        Test t = new Test("zhangsan",20);
////        System.out.println(t.toString());
//
//    }
//    public static void main(String[] args) {
//        Test t = new Test("zhangsan",20);
//        Test t1 = new Test("zhangsan",20);
//        System.out.println(t.equals(t1));
    //重写之后为同类的比较内部数据是否相同
//    public static void main(String[] args) {
//        String str1 = "hello world";
//        StringBuilder sb = new StringBuilder();
//        sb.append("hello world");
//        System.out.println(str1.equals(sb));
//        //Suspicious call to 'equals()' on 'StringBuilder' object
//        //false是因为不是String类型的
//        System.out.println(sb.equals(str1));
//        //地址不同
//
//    }
//    public static void main(String[] args) throws CloneNotSupportedException {
//        //克隆 -- 浅克隆 + 深克隆
//        //克隆的是对象内部的数据
//        //克隆protected修饰所有必须重写
////        Test t = new Test("zhangsan",20);
////        Test t1 = new Test();
////        Object clone = t.clone();
////        System.out.println(clone.toString());
//        //浅克隆
////        Test test = new Test("zhangsan",20);
////        Object clone = test.clone();
//
//    }
//    public static void main(String[] args) throws CloneNotSupportedException {
//        //深克隆和浅克隆的区别是就是数组的不同
////        Test t = new Test("zhangsan",20);
////        Test clone = (Test)t.clone();
////        Arrays.fill(clone.getArr(),0);
////        for (int i = 0; i < clone.getArr().length; i++) {
////            System.out.print(clone.getArr()[i] + " ");
////        }
////        System.out.println();
////        for (int i = 0; i < t.getArr().length; i++) {
////            System.out.print(t.getArr()[i] + " ");
////        }
//        //两个数组就不相同了
//
//
//
//
//    }
//    public static void main(String[] args) {
////        int[] arr = null;
////        //判断是否是null
////        System.out.println(Objects.isNull(arr));
////        //判断是否不是null
////        System.out.println(Objects.nonNull(arr));
//        //和Object里面的equals区别是判断了t1是否是null
//        Test t1 = new Test("zhangsan",20);
//        Test t2 = new Test("zhangsan",20);
//        System.out.println(Objects.equals(t1, t2));
//
//
//    }
//    public static void main(String[] args) {
    //Arrays类
//        Integer[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    //System.out.println(Arrays.toString(arr));
    //给数组查索引
    //没有-插入值-1
    //System.out.println(Arrays.binarySearch(arr,11));
//        int[] ints = Arrays.copyOf(arr, 10);
//        for (int i = 0; i < ints.length; i++) {
//            System.out.print(ints[i] + " ");
//        }
    //保前不保后
//        int[] ints = Arrays.copyOfRange(arr, 6, 10);
//        for (int i = 0; i < ints.length; i++) {
//            System.out.print(ints[i] + " ");
//        }
//        int[] arr2 = new int[10];
//        Arrays.fill(arr2,100);
//        for (int i = 0; i < arr2.length; i++) {
//            System.out.print(arr2[i] + " ");
//        }
    //默认正序排列
//        Arrays.sort(arr);
//        for (int i = 0; i < arr.length; i++) {
//            System.out.print(arr[i] + " ");
//        }
    //修改排序规则
//        Arrays.sort(arr,new Comparator<Integer>(){
//            @Override
//            public int compare(Integer o1, Integer o2) {
//                return o2 - o1;
//            }
//        });
//        for (int i = 0; i < arr.length; i++) {
//            System.out.print(arr[i] + " ");
//        }
//      @FunctionalInterface
    //@FunctionalInterface
    //lambda表达式
//        Integer[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
////        Arrays.sort(arr, (o1,o2) -> o2-o1);
////        for (int i = 0; i < arr.length; i++) {
////            System.out.print(arr[i] + " ");
////        }
//        Arrays.sort(arr, new Comparator<Integer>() {
//            @Override
//            public int compare(Integer o1, Integer o2) {
//                return o2 - o1;
//            }
//        });
//    }
//    public static void main(String[] args) {
//        //数组toString的实现
////        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
////        System.out.println(ArrtoStrign(arr));
////    }
////    public static String ArrtoStrign(int[] arr){
////        StringBuilder sb = new StringBuilder();
////        sb.append("[");
////        for (int i = 0; i < arr.length; i++) {
////            if(i == arr.length - 1){
////                sb.append(arr[i]);
////            }else {
////                sb.append(arr[i] + ", ");
////            }
////        }
////        sb.append("]");
////        return sb.toString();
////    }
//        //copyOf
////        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
////        Integer[] ints = ArrCopy(arr);
////        for (int i = 0; i < ints.length; i++) {
////            System.out.print(ints[i] + " ");
////        }
////    }
////
////    public static Integer[] ArrCopy(int[] arr) {
////        Integer[] arrCopy = new Integer[arr.length];
////        for (int i = 0; i < arr.length; i++) {
////            arrCopy[i] = arr[i];
////        }
////        Arrays.sort(arrCopy,new Comparator<Integer>(){
////            @Override
////            public int compare(Integer o1, Integer o2) {
////                return o2 - o1;
////            }
////        });
////        return arrCopy;
////    }
//        //copyOfRange
////        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
////        int[] arr1 = getArr(arr,4,10);
////        for (int i = 0; i < arr1.length; i++) {
////            System.out.print(arr1[i] + " ");
////        }
////
////
////    }
////    public static int[] getArr(int[] arr,int index1,int index2){
////        int[] arr2 = new int[index2 - index1];
////        int num = 0;
////        for (int i = index1; i < index2; i++) {
////            arr2[num] = arr[i];
////            num++;
////        }
////        return arr2;
////    }
//
//}
//    public static void main(String[] args) {
////        getMaxArray(new Supplier<Integer>() {
////            @Override
////            public Integer get() {
////                int[] arr = {1, 4, 2, 3, 6, 5, 9, 10, 7, 8};
////                Arrays.sort(arr);
////                return arr[arr.length - 1];
////            }
////        });
//        //lambda表达式
////        getMaxArray(() -> {
////            int[] arr = {1, 4, 2, 3, 6, 5, 9, 7, 9};
////            Arrays.sort(arr);
////            return arr[arr.length - 1];
////        });
////        getCharString(new Consumer<String>() {
////            @Override
////            public void accept(String s) {
////                char[] arr = s.toCharArray();
////                for (int i = 0; i < arr.length; i++) {
////                    System.out.print(arr[i] + " ");
////                }
////            }
////        });
////
////
////        getString(new Function<char[], String>() {
////            @Override
////            public String apply(char[] chars) {
////                String str = new String(chars);
////                return str;
////            }
////        }, new Function<String, byte[]>() {
////            @Override
////            public byte[] apply(String s) {
////                byte[] bytes = s.getBytes();
////                return bytes;
////            }
////        });
////        getReady(new Predicate<Integer>() {
////            @Override
////            public boolean test(Integer age) {
////                if(age<18||age>40){
////                    return false;
////                }else {
////                    return true;
////                }
////            }
////        });
////
////    }
//
//        //Supplier只取不给
////    public static void getMaxArray(Supplier<Integer> supplier) {
////        Integer ret = supplier.get();
////        System.out.println(ret);
////    }
//
//        //Consumer只给不取
////    public static void getCharString(Consumer<String> consumer){
////        consumer.accept("hello world");
////    }
//    //andthen -- 分别传参给两个
//
//    //Function给取全都有
////    public static void getString(Function<char[], String> function1,Function<String,byte[]> function2) {
////        char[] arr = {'a','b','c','d','e','f','g','h'};
////        byte[] ret = function1.andThen(function2).apply(arr);
////        for (int i = 0; i < ret.length; i++) {
////            System.out.print(ret[i] + " ");
////        }
////    }
//    //传参1 -> 2；
//
//    //Predicate要给返回Boolean
////    public static void getReady(Predicate<Integer> predicate) {
////        Scanner sc = new Scanner(System.in);
////        System.out.println("请输入你所想要的数字：");
////        boolean ret = predicate.test(sc.nextInt());
////        System.out.println(ret);
////    }
//    //and -- &&
//    //or -- ||
//    //negate -- not
//
//
//
//}
    public static void main(String[] args) {
        //内置类接口
        /**
         * （1） Supplier
         * （2） Consumer
         * （3） Function
         * （4） Predicate
         * */



    }



}